package com.zgkxzx.mvvmbase.view.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;

import com.zgkxzx.mvvmbase.BR;
import com.zgkxzx.mvvmbase.R;
import com.zgkxzx.mvvmbase.bean.picture.PictureBean;
import com.zgkxzx.mvvmbase.databinding.ActivityMainBinding;
import com.zgkxzx.mvvmbase.view.adapter.PicturesAdapter2;
import com.zgkxzx.mvvmbase.viewmodel.MainViewModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建者 zgkxzx
 * 日期   2/1/18
 * 描述
 */

public class MainActivity extends BaseActivity<ActivityMainBinding, MainViewModel> implements MainViewModel.OnDataListener {
    private static final String TAG = MainActivity.class.getSimpleName();

    private List<PictureBean> results = new ArrayList<>();
    private PicturesAdapter2 picturesAdapter2;


    @Override
    protected int getBrId() {
        return BR.mainViewModel;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected MainViewModel getViewModel(Context context) {
        return new MainViewModel(context, this);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1,
                StaggeredGridLayoutManager.VERTICAL);
        viewBinding.rvPictureList.setLayoutManager(layoutManager);
        picturesAdapter2 = new PicturesAdapter2(this, results);
        viewBinding.rvPictureList.setAdapter(picturesAdapter2);
    }

    @Override
    public void onData(List<PictureBean> results) {
        Log.d(TAG, " 加载更新数据。。。");
        if (results != null && results.size() > 0) {
            this.results.addAll(results);
            picturesAdapter2.notifyDataSetChanged();
        }

    }
}
